use std::{io, cmp::Ordering};
use rand::Rng;

fn main() {
    println!("Hello, world!");
    println!("猜数");
    let secret_number = rand::thread_rng().gen_range(1..101);
    println!("num:{}", secret_number);
    loop {
        let mut guess = String::new();
        io::stdin().read_line(&mut guess).expect("无法读取");

        // shadow
        let guess:u32 = match guess.trim().parse() {
            Ok(num) => num,
            Err(_) => continue,
        };

        println!("你猜的是：{}", guess);

        match guess.cmp(&secret_number) {
            Ordering::Less => println!("Too small"),
            Ordering::Greater => println!("Too big"),
            Ordering::Equal => {
                println!("You win!");
                break;
            }
        }
    }
}
